package com.atguigu.controller;


import com.alibaba.dubbo.config.annotation.Reference;

import com.atguigu.common.MessageConstant;
import com.atguigu.pojo.TravelGroup;
import com.atguigu.service.TravelGroupService;
import com.atguigu.vo.PageResult;
import com.atguigu.vo.QueryPageBean;
import com.atguigu.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/TravelGroup")
public class TravelGroupController {


    @Reference
    TravelGroupService travelGroupService;

    @RequestMapping("/add")
    public Result add(@RequestBody TravelGroup travelGroup,Integer[] travelItemIds){

        travelGroupService.add(travelGroup, travelItemIds);
        return new Result(true, MessageConstant.ADD_TRAVELGROUP_SUCCESS);
    }
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult =travelGroupService.findPage(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }
    @RequestMapping("/findTravelItemIdByTravelgroupId")
    public List<Integer> findTravelItemIdByTravelgroupId(Integer id){
        List<Integer> list =travelGroupService.findTravelItemIdByTravelgroupId(id);
        return list;
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        TravelGroup travelGroup=travelGroupService.findById(id);
        return  new Result(true, MessageConstant.QUERY_TRAVELGROUP_SUCCESS,travelGroup);

    }
    @RequestMapping("/edit")
    public Result edit(Integer[] travelItemIds, @RequestBody TravelGroup travelGroup){
        travelGroupService.edit(travelItemIds,travelGroup);
        return new Result(true,MessageConstant.EDIT_TRAVELGROUP_SUCCESS);
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        List<TravelGroup> list=travelGroupService.findAll();
        if (list !=null&&list.size()>0){
            Result result=new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,list);
            return result;
        }else{
            Result result=new Result(false,MessageConstant.QUERY_SETMEAL_SUCCESS);
            return result;
        }

    }
}
